﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Computer_Manager.DTO;
using Computer_Manager.BUS;

namespace Computer_Manager.GUI
{
    public partial class frmInfoCompany : DevExpress.XtraEditors.XtraForm
    {
        DTO_company company = null;
        BUS_company bus_com = new BUS_company();
        public frmInfoCompany()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmInfoCompany_Load(object sender, EventArgs e)
        {
            var dt_com = bus_com.GetAll();
            if (dt_com.Rows.Count>0)
            {
                txtName.Text = dt_com.Rows[0]["company"].ToString();
                txtAddress.Text = dt_com.Rows[0]["address"].ToString();
                txtTel.Text = dt_com.Rows[0]["tel"].ToString();
                txtFax.Text = dt_com.Rows[0]["fax"].ToString();
                txtWeb.Text = dt_com.Rows[0]["webSite"].ToString();
                txtEmail.Text = dt_com.Rows[0]["email"].ToString();
                txtMST.Text = dt_com.Rows[0]["tax"].ToString();
            }
            

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            company = new DTO_company();
            company.company_id = 1;
            company.company = txtName.Text;
            company.address = txtAddress.Text;
            company.tel = txtTel.Text;
            company.fax = txtFax.Text;
            company.webSite = txtWeb.Text;
            company.email = txtEmail.Text;
            company.tax = txtMST.Text;
            if (bus_com.company_Update(company))
            {
                XtraMessageBox.Show("Thông tin đã được lưu.","Thông tin",MessageBoxButtons.OK,MessageBoxIcon.Information);
            } 
        }

        
    }
}